package cn.koala.key.receipt.controller;

import cn.koala.key.entity.BorrowOrderReturn;
import cn.koala.key.receipt.dto.BorrowOrderReturnDTO;
import cn.koala.key.receipt.service.BorrowOrderReturnService;
import cn.ehi.authority.annotation.WebAuthentication;
import cn.seed.common.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description:借用单归还信息
 * @author 32415
 * @time 2019/04/28
 **/
@RestController
@RequestMapping("/borrow-order-returns")
@Api(value = "BorrowOrderReturn",tags = "借用单归还信息")
public class BorrowOrderReturnController {

    @Autowired
    private BorrowOrderReturnService borrowOrderReturnService;

    @ApiOperation(value = "获取归还信息")
    @GetMapping("/{orderNo}")
    public Result<BorrowOrderReturn> getByOrderNo(@PathVariable String orderNo) {
        return borrowOrderReturnService.getByOrderNo(orderNo);
    }

    @ApiOperation(value = "新建归还信息")
    @PostMapping()
    @WebAuthentication(systemCode = "KoalaKey",moduleIds = "KOALAKEY_B_00007")
    public Result create(@RequestBody BorrowOrderReturn borrowOrderReturn) {
        return borrowOrderReturnService.create(borrowOrderReturn);
    }

    /**
     * @Description: 修改key_info， key_inventory表中的钥匙状态为在库，生成入库单，入库明细
     *
     * @param
     * @return Object
     * @throws
     * @exception:
     * @author: 32415
     * @time: 2019/5/6 16:00
     */
    @ApiOperation(value = "确认归还")
    @PostMapping("/confirm")
    @WebAuthentication(systemCode = "KoalaKey",moduleIds = "KOALAKEY_B_00008")
    public Result confirmReturn(@RequestBody BorrowOrderReturnDTO borrowOrderReturnDTO) {
        return borrowOrderReturnService.confirmReturn(borrowOrderReturnDTO);
    }
}
